﻿<!--
    Project: Web Dev Assignment 4
    File: name.aspx
    Author: Ryan Pink
    Date Modified: November 19, 2013
    Description: 
        This source page loads in the content frame of the name entry page. This page requests a name and high number
        to POST to the game.aspx page. Each input is validated using ASP.NET validators.
-->

<%@ Page Language="C#" Debug="true" %>

<script runat="server">

    /*
     * RefreshSession()
     * Parameters:
     *  object sender: the object that called the method
     *  EventArgs e   : system arguments associated with the call
     */
    protected void RefreshSession(object sender, EventArgs e)
    {
        // create a new session
        Session.Abandon();
    }

</script>

<script type="text/javascript">

    /*
     * highNumberRangeValidate()
     * Parameters:
     *  sender: the object that called the method
     *  args  : system arguments associated with the call
     */
    function highNumberRangeValidate( sender, args ) {
    
        // limit the number to between 1 and 1,000,000
        if ( args.Value > 1 && args.Value <= 1000000 ) {
        
            args.IsValid = true;
        } else {
        
            args.IsValid = false;
        }
    }

</script>

<html xmlns="http://www.w3.org/1999/xhtml">

<head runat="server">
    <title></title>
    <link href="style.css" rel="stylesheet" />
</head>

<body>
    <!-- This placeholder tag loads the session information when the page loads. -->
    <asp:PlaceHolder ID="refreshSession" runat="server" OnLoad="RefreshSession" />

    <table>
    <tr><td style="width: 60%;">

    <!-- This is the main form for the Hi-Lo game. This page uses it to accept a name and high number to start. -->
    <form id="frmHiLo" runat="server" method="post" action="game.aspx" defaultfocus="player_name">
        <div class="content">
            <h3>First Things First. ::.</h3><br />
            
            What is your name?
            <asp:TextBox id="player_name" runat="server" /> 
            
            <!------------ Player Name Validators ------------>

            <!-- Validate the name is entered (i.e. not empty) -->
            <asp:RequiredFieldValidator id="playerNameRequired" 
                                        runat="server" 
                                        ControlToValidate="player_name" 
                                        ErrorMessage="<br />Your name is required." 
                                        Display="Dynamic"
                                        ForeColor="Red" />

            <!-- Validate the name against allowed characters -->
            <asp:RegularExpressionValidator id="playerNameRegex"
                                            runat="server"
                                            ControlToValidate="player_name" 
                                            ValidationExpression="[A-Za-z]{2,20}" 
                                            ErrorMessage="<br />Please enter a name using letters from 2 to 20 characters long." 
                                            Display="Dynamic"
                                            ForeColor="Red" />

            <br /><br /><br />
            
            <h3>Something measurable? ::.</h3><br />
            
            Now pick a number.
            <asp:TextBox ID="high_number" runat="server" /> 
            
            <!------------ High Number Validators ------------>

            <!-- Validate the number is entered (i.e. not empty) -->
            <asp:RequiredFieldValidator ID="highNumberRequired" 
                                        runat="server" 
                                        ControlToValidate="high_number" 
                                        ErrorMessage="<br />A number is required." 
                                        Display="Dynamic"
                                        ForeColor="Red" />

            <!-- Validate the number is in fact a number -->
            <asp:CompareValidator ID="highNumberCompare" 
                                  runat="server" 
                                  ControlToValidate="high_number" 
                                  Type="Integer"
                                  Operator="DataTypeCheck"
                                  ErrorMessage="<br />Please enter an integer number." 
                                  Display="Dynamic"
                                  ForeColor="Red" />

            <!-- Validate the number against a custom js validation -->
            <asp:CustomValidator ID="highNumberRange"
                                 runat="server"
                                 ControlToValidate="high_number"
                                 ClientValidationFunction="highNumberRangeValidate"
                                 ErrorMessage="<br />Please enter a number between 2 and 1,000,000."
                                 Display="Dynamic"
                                 ForeColor="Red" />
            
            <br />

            <asp:Button ID="btnSubmit" Runat=server Text="That's Me!" PostBackUrl="game.aspx" />
            <asp:Button ID="btnReset" runat="server" Text="Wait, Let's Start Over..." OnClientClick="this.form.reset();" />
        </div>
    </form>

    <!-- This section is used to provide information to the user. -->
    </td><td class="guide">

        <div class="header" style="position: relative; top: -3px;">
            <h2>Hiya! ::.</h2>
        </div>
        <div class="content">
            <p><b>Welcome to the 4th iteration of the Hi-Lo Game!</b></p>
            <p><b>Here's how to play:</b></p>
            <blockquote>
                <i>The player gives a large number, and the game picks a random number between 1 and that number. 
                Then the player attempts to guess the random number, each time being told whether they are
                too high or too low.<br /><br />

                When the player guesses correctly, <b>they win!</b></i>
            </blockquote>
            <p><b>It's as easy as falling off a log! Just give a name and high number.</b></p>
        </div>

    </td></tr>
    </table>
</body>

</html>
